/////////////////////////
// 	DDCHECKBOX.cpp	:	v0010
//	Written by 		:	Li	Haijun
//	Compiler		:	Microsoft Visual C++ 4.0
//	v0010			:	Nov.13.1996
/////////////////////////
#include	<stdio.h>
#include	"stdafx.h"

#include	"Assert.h"
#include	"DDCompo.h"


#include	"DDCheck.h"
#include	"ddmenu.h"
#include	"Marco.h"
#include	"cbgame.h"

////////////////////////////
#include "l_allbmp.h"
extern char	bmpfilename[30];
extern char	listfilename[30];
/////////////////////////////////////

/////////////////////////////////////////////////
//	to restore all check-box's pointer
class	CDDCheckBoxUnit	*	pAllCheckBoxUnit[MAX_CHECKBOXUNIT];
////////////////////////////////////////////////////
// major parameter for bitmap(it record the current state of operate)
class	CDDCheckBox *	pCurrentCheckBox = NULL;	// a pointer point to the current check-box
class	CDDCheckBox *	pPreviousCheckBox = NULL;	// a pointer point to the previous check-box
int		nPreviousCheckBoxState = NONE;	// previous check-box's state,0-uncheck-up,1-uncheck-down,2-check-up,3-check-down,4-disable
int		nCurrentCheckBoxState = NONE;	// current check-box's state,0-uncheck-up,1-uncheck-down,2-check-up,3-check-down,4-disable

////////////////////////////////////
//	       all menu
////////////////////////////////////
extern	CDDMenu		* CurrentMenu;
extern	CDDMenu		Menu_Main;
extern	CDDMenu		Menu_NewGame;
extern	CDDMenu		Menu_MainLoad;
extern	CDDMenu		Menu_NetWork;
extern	CDDMenu		Menu_NetWork_InputName;
extern	CDDMenu		Menu_NetWork_Serial;
extern	CDDMenu		Menu_NetWork_Internet;
extern	CDDMenu		Menu_NetWork_Ipx;
extern	CDDMenu		Menu_NetWork_SetNet;
extern	CDDMenu		Menu_NetWork_SetNet_SelectMap;
extern	CDDMenu		Menu_NetWork_SetNet_SelectKing;
extern	CDDMenu		Menu_NetWork_Modem;
/////////////////////////////
//	system menu structure
extern	CDDMenu		Menu_System;
extern	CDDMenu		Menu_System_Save;
extern	CDDMenu		Menu_System_Load;
extern	CDDMenu		Menu_System_Query;
extern	CDDMenu		Menu_System_Query_General_1;
extern	CDDMenu		Menu_System_Query_General_2;
extern	CDDMenu		Menu_System_Query_Army;
extern	CDDMenu		Menu_System_Query_Building;
extern	CDDMenu		Menu_System_Query_Campaign_Mission;
extern	CDDMenu		Menu_System_Option;
extern	CDDMenu		Menu_System_Help;
extern	CDDMenu		Menu_System_Help_Operate;
extern	CDDMenu		Menu_System_Help_Icon;
extern	CDDMenu		Menu_System_Help_Game;
extern	CDDMenu		Menu_System_Exit;
///////////////////////////
//	menu to select general
extern	CDDMenu		Menu_Select_General;
//	menu to show the information of the generals want to single battle
extern	CDDMenu		Menu_Single ;
extern	CDDMenu		Menu_Single_Reject ;
extern	CDDMenu		Menu_Single_Result ;
/////////////////////////////////////////////////
//	construct function
CDDCheckBox::CDDCheckBox()
{
	m_nFileNameId = NONE;
	m_szOneBitmap.cx = 0L;
	m_szOneBitmap.cy = 0L;

	m_rTotal.left	= 0L;
	m_rTotal.top	= 0L;
	m_rTotal.right	= 0L;
	m_rTotal.bottom	= 0L;

	m_rCurrent.left	= 0L;
	m_rCurrent.top	= 0L;
	m_rCurrent.right	= 0L;
	m_rCurrent.bottom	= 0L;

	m_dwX = 0;	m_dwY = 0;
	m_bSet = FALSE;

	m_nID = 0;
	m_nState = CHECKBOX_NOCHECK_UP;
	m_nPart = 0;

	m_bEnableSound = TRUE;
}
/////////////////////////////////////////////////
//	disconstruct function
CDDCheckBox::~CDDCheckBox( )
{
	Release();
	m_nFileNameId = NONE;
	m_bSet = FALSE;
	m_bEnableSound = TRUE;
}
BOOL CDDCheckBox::PreLoad(int FilenameId, int x, int y,
						int OneBitmapWidth/*=0*/, int OneBitmapHeight/*=0*/)
{
	char	fname[20];

	HRESULT			ddrval;
	DDSURFACEDESC	ddsd;

//////////////////////////////////////////////////
	_itoa( FilenameId, fname, 10 );

	class CPicture_imageall picture;

	picture.image_open_compress(bmpfilename);
	picture.image_open_index(listfilename);
	picture.LoadBitmap( &m_BitmapSurface, FilenameId );
	picture.image_close_index();
	picture.image_close_compress();

/////////////////////////////////////////////////////////
	// to set the value of m_FileName
	m_nFileNameId = FilenameId;	//set the member veriable m_FileName
    //
    // get size of surface.
    //
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;

    ddrval = m_BitmapSurface.GetSurface()->GetSurfaceDesc(&ddsd);
	if(ddrval != DD_OK)
		return FALSE;
	m_rTotal.left = m_rTotal.top = 0;
	m_rTotal.right = ddsd.dwWidth;
	m_rTotal.bottom = ddsd.dwHeight;
// to set the value of m_szOneBitmap
	if( (OneBitmapWidth==0)&&(OneBitmapHeight==0) )
	{
		// I assume that all single bitmaps' height is equal to it's width
		if(m_rTotal.bottom > m_rTotal.right)
			m_szOneBitmap.cx = m_szOneBitmap.cy = m_rTotal.right;
		else
			m_szOneBitmap.cx = m_szOneBitmap.cy = m_rTotal.bottom;
		// to set the value of m_rCurrent
		m_rCurrent.left = m_rCurrent.top = 0;
		m_rCurrent.right = m_rCurrent.bottom = m_szOneBitmap.cx;
	}
	else if( OneBitmapWidth * OneBitmapHeight == 0 )
		return FALSE;
	else
	{
		// I assume that all single bitmaps' height is not equal to it's width
		m_szOneBitmap.cx = OneBitmapWidth;
		m_szOneBitmap.cy = OneBitmapHeight;
		// to set the value of m_rCurrent
		m_rCurrent.left = m_rCurrent.top = 0;
		m_rCurrent.right = 	OneBitmapWidth;
		m_rCurrent.bottom = OneBitmapHeight;
	}
//to set the value of m_dwX, m_dwY
	m_dwX = x; m_dwY = y;

	return TRUE;
}
// to set the id of this check-box
void CDDCheckBox::SetID(int ID)
{
	m_nID = ID ;	// button id
	return ;
}
// to set the state of this check-box
void	CDDCheckBox::SetState( int state/*=-1*/ )
{
	if( state == -1 )
		m_nState = (m_nState+1)%4 ;  // to set this check-box's state
	else
	{
		m_nState = state;
	}

	if( state == CHECKBOX_HIDE )
		return ;
	if( m_szOneBitmap.cx == m_rTotal.right )
	{
		m_rCurrent.left = m_rTotal.left;
		m_rCurrent.top = m_rTotal.top + m_nState * m_szOneBitmap.cy;
		m_rCurrent.right = m_rCurrent.left + m_szOneBitmap.cx;
		m_rCurrent.bottom = m_rCurrent.top + m_szOneBitmap.cy;
	}
	else
	{
		m_rCurrent.left = m_rTotal.left + m_nState * m_szOneBitmap.cx;
		m_rCurrent.top = m_rTotal.top;
		m_rCurrent.right = m_rCurrent.left + m_szOneBitmap.cx;
		m_rCurrent.bottom = m_rCurrent.top + m_szOneBitmap.cy;
	}
}
//to get the state of this check-box 
int		CDDCheckBox::GetState()
{
	return m_nState;
}
// to send a message when you changed the state of a check-box
void CDDCheckBox::SendMessage(int	state)
{
	if( CurrentMenu == &Menu_NetWork_SetNet )
	{
		// to post the message to others your state
		if( state == CHECKBOX_CHECK_UP )
		{
//			PostMessage(hwndGame, WM_COMMAND, m_nID, 0);
			switch(m_nID)
			{
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE1 :
				{
					GAME_bNetPlayerOK[1] = TRUE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE1, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE2 :
				{
					GAME_bNetPlayerOK[2] = TRUE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE2, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE3 :
				{
					GAME_bNetPlayerOK[3] = TRUE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE3, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE4 :
				{
					GAME_bNetPlayerOK[4] = TRUE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE4, 0);
				}
				break;
			////////////////////////////////////////////////////////////////////
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY11 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY12 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY12, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY21, 0);
//					pAllCheckBoxUnit[4]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[4]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY13 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY13, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY31, 0);
//					pAllCheckBoxUnit[8]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[8]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY14 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY14, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY41, 0);
//					pAllCheckBoxUnit[12]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[12]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY21 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY21, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY12, 0);
//					pAllCheckBoxUnit[1]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[1]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY22 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY23 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY23, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY32, 0);
//					pAllCheckBoxUnit[9]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[9]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY24 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY24, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY42, 0);
//					pAllCheckBoxUnit[13]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[13]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY31 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY31, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY13, 0);
//					pAllCheckBoxUnit[2]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[2]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY32 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY32, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY23, 0);
//					pAllCheckBoxUnit[6]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[6]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY33 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY34 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY34, 0);
//					pAllCheckBoxUnit[14]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[14]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY41 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY41, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY14, 0);
//					pAllCheckBoxUnit[3]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[3]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY42 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY42, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY24, 0);
//					pAllCheckBoxUnit[7]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[7]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY43 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY43, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY34, 0);
//					pAllCheckBoxUnit[11]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[11]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY44 :
				break;
			}
		}
		else if( state == CHECKBOX_NOCHECK_UP)
		{
			switch(m_nID)
			{
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE1 :
				{
					GAME_bNetPlayerOK[1] = FALSE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOAGREE1, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE2 :
				{
					GAME_bNetPlayerOK[2] = FALSE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOAGREE2, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE3 :
				{
					GAME_bNetPlayerOK[3] = FALSE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOAGREE3, 0);
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_AGREE4 :
				{
					GAME_bNetPlayerOK[4] = FALSE ;
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOAGREE4, 0);
				}
				break;
			////////////////////////////////////////////////////////////////////
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY11 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY12 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY12, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY21, 0);
//					pAllCheckBoxUnit[4]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[4]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY13 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY13, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY31, 0);
//					pAllCheckBoxUnit[8]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[8]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY14 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY14, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY41, 0);
//					pAllCheckBoxUnit[12]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[12]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY21 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY21, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY12, 0);
//					pAllCheckBoxUnit[1]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[1]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY22 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY23 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY23, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY32, 0);
//					pAllCheckBoxUnit[9]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[9]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY24 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY24, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY42, 0);
//					pAllCheckBoxUnit[13]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[13]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY31 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY31, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY13, 0);
//					pAllCheckBoxUnit[2]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[2]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY32 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY32, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY23, 0);
//					pAllCheckBoxUnit[6]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[6]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY33 :
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY34 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY34, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY43, 0);
//					pAllCheckBoxUnit[14]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[14]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY41 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY41, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY14, 0);
//					pAllCheckBoxUnit[3]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[3]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY42 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY42, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY24, 0);
//					pAllCheckBoxUnit[7]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[7]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY43 :
				{
					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY43, 0);
//					PostMessage(hwndGame, WM_COMMAND, BUTTON_MENU_MAIN_NETWORK_SETNET_NOALLY34, 0);
//					pAllCheckBoxUnit[11]->m_pCheckBox[0]->SetState(state) ;
//					pAllCheckBoxUnit[11]->m_pCheckBox[0]->Show() ;
				}
				break;
			case BUTTON_MENU_MAIN_NETWORK_SETNET_ALLY44 :
				break;
			}
		}
	}
}

//to test whether the given point is on this check-box
BOOL CDDCheckBox::OnCheckBox( int x, int y)
{
	int	m_nLeftEdge = m_dwX;
	int m_nRightEdge = m_nLeftEdge + (int)m_szOneBitmap.cx;
	int m_nTopEdge = m_dwY;
	int m_nBottomEdge = m_nTopEdge + (int)m_szOneBitmap.cy;

	if( (x >= m_nLeftEdge)&&(x <= m_nRightEdge )
	  &&(y >= m_nTopEdge )&&(y <= m_nBottomEdge) )
		return TRUE;
	else
		return FALSE;
}
// to show this check-box
void	CDDCheckBox::Show()
{
/*	if( m_nState == CHECKBOX_HIDE )
		return ;

	POINT	ptDest;

	ptDest.x = m_dwX;
	ptDest.y = m_dwY;
	
	m_BitmapSurface.BltToBack(ptDest, &m_rCurrent);
	
	RECT	ShowRect;
	ShowRect.left = m_dwX,	ShowRect.top = m_dwY;
	ShowRect.right = m_dwX + m_szOneBitmap.cx;
	ShowRect.bottom = m_dwY + m_szOneBitmap.cy;
	DDC_UpdateScreen( );//&ShowRect );		*/
	Blit();
	Update();
}
// to blit this check-box to back buffer
void CDDCheckBox::Blit(void)
{
	if( m_nState == CHECKBOX_HIDE )
		return ;

	POINT	ptDest;

	ptDest.x = m_dwX;
	ptDest.y = m_dwY;
	
	m_BitmapSurface.BltToBack(ptDest, &m_rCurrent);
}
// to update the area of this check-box from back buffer to front buffer
void CDDCheckBox::Update(void)
{
	
	RECT	ShowRect;
	ShowRect.left = m_dwX,	ShowRect.top = m_dwY;
	ShowRect.right = m_dwX + m_szOneBitmap.cx;
	ShowRect.bottom = m_dwY + m_szOneBitmap.cy;
	DDC_UpdateScreen( &ShowRect );
}
// to release this button's pointer
void CDDCheckBox::Release()
{
	// release the surface that this button's bitmap used
	m_BitmapSurface.Release();
}
///////////////////////////////////////////////////
// to define all member function of CDDUnit
///////////////////////////////////////////////////
// construct
CDDCheckBoxUnit::CDDCheckBoxUnit()
{
	m_nSerialNum = NONE;

	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		m_pCheckBox[i] = NULL;
	}
}
//	disconstruc
CDDCheckBoxUnit::~CDDCheckBoxUnit()
{
	Release();
	m_nSerialNum = NONE;
}
// to set state of each LIST that in this list-unit
void	CDDCheckBoxUnit::SetMemberState( int state )
{
	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		if( (m_pCheckBox[i] != NULL)&&(m_pCheckBox[i]->GetState() != CHECKBOX_DISABLE) )
		{
			m_pCheckBox[i]->SetState(state);
			m_pCheckBox[i]->Show();
		}
	}
}
void	CDDCheckBoxUnit::Show( )
{
	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		if( m_pCheckBox[i] != NULL )
		{
			m_pCheckBox[i]->Show();
		}	
	}
}
// to blit all check-boxes in this checkbox-unit to back buffer
void	CDDCheckBoxUnit::Blit( )
{
	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		if( m_pCheckBox[i] != NULL )
		{
			m_pCheckBox[i]->Blit();
		}	
	}
}
// to update the area of every checkbox in this checkbox-unit from back buffer to front buffer
void	CDDCheckBoxUnit::Update( )
{
	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		if( m_pCheckBox[i] != NULL )
		{
			m_pCheckBox[i]->Update();
		}	
	}
}
// to release every check-box of this check-box unit
void	CDDCheckBoxUnit::Release()
{
	for( int i=0; i<MAX_CHECKBOXINUNIT; i++ )
	{
		if( m_pCheckBox[i] != NULL )
		{
			delete m_pCheckBox[i];
			m_pCheckBox[i] = NULL;
		}
	}
}
/////////////////////////////////////////
// to test whether a check-box is clicked --- WM_LBUTTONDOWN
/////////////////////////////////////////
BOOL	LeftButtonDownOnCheckBox(int xPos, int yPos)
{
	for( int i=0; i<MAX_CHECKBOXUNIT; i++ )
	{
		if( pAllCheckBoxUnit[i] != NULL )
		{
			for(int j=0; j<MAX_CHECKBOXINUNIT; j++)
			{
				if( (pAllCheckBoxUnit[i]->m_pCheckBox[j] != NULL)
//				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_DISABLE)
//				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_HIDE)
				  &&( (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_NOCHECK_UP) || 
				      (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_CHECK_UP)
					)
				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->OnCheckBox(xPos, yPos)) )
				{
					// set the just been clicked button's state
					pAllCheckBoxUnit[i]->m_pCheckBox[j]->SetState( );
					pAllCheckBoxUnit[i]->m_pCheckBox[j]->Show( );
					// to set the global button's state
					pCurrentCheckBox = pAllCheckBoxUnit[i]->m_pCheckBox[j];
					nCurrentCheckBoxState = pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState();
					return TRUE;
				}
			}
		}
	}	
	pCurrentCheckBox = NULL;
	return FALSE;
}
// to test whether cursor is on current check-box when left button up --- WM_LBUTTONUP
BOOL	LeftButtonUpOnCheckBox(int xPos, int yPos)
{
	for( int i=0; i<MAX_CHECKBOXUNIT; i++ )
	{
		if(	pAllCheckBoxUnit[i] != NULL )
		{
			for(int j=0; j<MAX_CHECKBOXINUNIT; j++)
			{
				if( (pAllCheckBoxUnit[i]->m_pCheckBox[j] != NULL)
				  &&(pCurrentCheckBox == pAllCheckBoxUnit[i]->m_pCheckBox[j])
//				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_DISABLE)
//				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_HIDE)
				  &&( (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_NOCHECK_DOWN) || 
				      (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_CHECK_DOWN)
					)
				  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->OnCheckBox(xPos, yPos)) )
				{
					// set the just been clicked button's state
					pAllCheckBoxUnit[i]->m_pCheckBox[j]->SetState( );
					pAllCheckBoxUnit[i]->m_pCheckBox[j]->Show( );
					// to set the global button's state
					pCurrentCheckBox = pAllCheckBoxUnit[i]->m_pCheckBox[j];
					nCurrentCheckBoxState = pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState( );

					if(nCurrentCheckBoxState == CHECKBOX_CHECK_UP)
					{
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->SetState(CHECKBOX_CHECK_UP) ;
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->SendMessage(CHECKBOX_CHECK_UP) ;
					}
					else if(nCurrentCheckBoxState == CHECKBOX_NOCHECK_UP)
					{
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->SetState(CHECKBOX_NOCHECK_UP) ;
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->SendMessage(CHECKBOX_NOCHECK_UP) ;
					}

					if(nCurrentCheckBoxState == CHECKBOX_CHECK_UP)
					{
						// to set the serial number to this check box
						pAllCheckBoxUnit[i]->m_nSerialNum = j;

						for(int k=0; k<MAX_CHECKBOXINUNIT; k++)
						{
							if( (pAllCheckBoxUnit[i]->m_pCheckBox[k] != NULL)
							  &&(pAllCheckBoxUnit[i]->m_pCheckBox[k]->GetState() == CHECKBOX_CHECK_UP)
							  &&(pAllCheckBoxUnit[i]->m_pCheckBox[k] != pAllCheckBoxUnit[i]->m_pCheckBox[j]) )
							{
								pAllCheckBoxUnit[i]->m_pCheckBox[k]->SetState(CHECKBOX_NOCHECK_UP);
								pAllCheckBoxUnit[i]->m_pCheckBox[k]->Show( );
							}
						}
					}
					else
						// to set the serial number to this check box
						pAllCheckBoxUnit[i]->m_nSerialNum = NONE;

					return TRUE;
				}
			}
		}
	}
	return FALSE;
}
/////////////////////////////////////////
// to test whether cursor is moved on a check-box --- WM_ONMOUSEMOVE
BOOL	MouseMoveOnCheckBox(WPARAM wParam,int xPos, int yPos)
{
	// If there is a check-box is pressed down, do this.
	if( wParam == MK_LBUTTON )
	{
		for( int i=0; i<MAX_CHECKBOXUNIT; i++ )
		{
			if(	pAllCheckBoxUnit[i] != NULL )
			{

				for(int j=0; j<MAX_CHECKBOXINUNIT; j++)
				{
					if( (pAllCheckBoxUnit[i]->m_pCheckBox[j] != NULL)
					  &&(pCurrentCheckBox == pAllCheckBoxUnit[i]->m_pCheckBox[j])
//					  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_DISABLE)
//					  &&(pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() != CHECKBOX_HIDE)
					  &&( (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_NOCHECK_DOWN) || 
					      (pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState() == CHECKBOX_CHECK_DOWN) 
						)
					  &&( ! pAllCheckBoxUnit[i]->m_pCheckBox[j]->OnCheckBox(xPos, yPos)) )
					{
						// set the current button to NULL beacuse of cursor has move out the button
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->
												SetState( pAllCheckBoxUnit[i]->m_pCheckBox[j]->GetState()-1 );
						pAllCheckBoxUnit[i]->m_pCheckBox[j]->Show();
						// to set the global button's state
						pCurrentCheckBox = NULL;
						nCurrentCheckBoxState = NONE;
						return TRUE;
					}
				}
			}
		}
	}
	return FALSE;
}

////////////////////////////////////////////////////////////////
// to delete all check-box in the volume of pAllCheckBoxUnit[MAX_CHECKBOXUNIT] array
void	FACE_DeleteAllCheckBox()
{
	for( int i=0; i<MAX_CHECKBOXUNIT; i++ )
	{
		if( pAllCheckBoxUnit[i] != NULL )
		{
			delete pAllCheckBoxUnit[i];
			pAllCheckBoxUnit[i] = NULL;
		}
	}
}
/////////////////////////////////////////
void	FACE_BlitAllCheckBox()
{
	for( int i=0; i<MAX_CHECKBOXUNIT; i++ )
	{
		if( pAllCheckBoxUnit[i] != NULL )
		{
			pAllCheckBoxUnit[i]->Blit() ;
		}
	}
}
/////////////////////////////////////////
